const jwt = require('jsonwebtoken');
const { think } = require('thinkjs');

module.exports = class extends think.Service {
  constructor() {
    super();
    const { secret, expiresIn } = think.config('jwt');
    this.secret = secret;
    this.expiresIn = expiresIn;
  }

  /**
   * 签发一个令牌
   * @param {object} payload jwt的载荷
   */
  sign(payload) {
    return jwt.sign(payload, this.secret, { expiresIn: this.expiresIn });
  }
};
